#include "GLRasterizerState.h"

#include <Rz/Graphics/Render/Libraries/OpenGL/GL.h>
#include <Rz/Graphics/Math/Vector3.h>

namespace Rz { namespace Graphics { namespace Render { namespace Libraries { namespace OpenGL {

GLRasterizerState::GLRasterizerState(IRenderDevice* renderDevice)
{
	this->SetRenderDevice(renderDevice);
}

void GLRasterizerState::Bind()
{
	IRasterizerState::Bind();

	GL::FrontFace(GL_CW);

	if (this->GetCullMode() == CullMode::None)
	{
		GL::Disable(GL_CULL_FACE);
		GL::CullFace(GL_FRONT_AND_BACK);
	}
	else
	{
		GL::Enable(GL_CULL_FACE);
		GL::CullFace(this->GetCullMode() == CullMode::None ? GL_FRONT_AND_BACK :
			this->GetCullMode() == CullMode::ClockwiseFace ? GL_FRONT : GL_BACK);
	}

	GL::PolygonMode(GL_FRONT_AND_BACK, this->GetFillMode() == FillMode::Wired ? GL_LINE : GL_FILL);

	if (this->GetScissorTestEnable())
	{
		GL::Enable(GL_SCISSOR_TEST);
	}
	else
	{
		GL::Disable(GL_SCISSOR_TEST);
	}
}

void GLRasterizerState::Unbind()
{
	IRasterizerState::Unbind();
}

} } } } } 
